#!/bin/bash
SCRIPT_BASE_DIR=$( dirname "${BASH_SOURCE[0]}" )
source "${SCRIPT_BASE_DIR}/common/fs_utils.sh"

cmd=$( basename "$0" )
if [ $# -ne 1 ]
then
	echo "Usage: ${cmd} <root_dir>"
	exit 1
fi

root="$1"
dir_exists_or_die "$1/source/gstone"
dir_exists_or_die "$1/include/gstone"
dir_exists_or_die "$1/tests"

csFile="${root}/cscope.files"
echo "Build ${csFile} ..."
find "${root}/source/gstone" -name "*.cpp" > "${csFile}"
find "${root}/source/gstone" -name "*.cc" >> "${csFile}"
# source下也有.h
find "${root}/source/gstone" -name "*.h" >> "${csFile}"
find "${root}/include/gstone" -name "*.h" >> "${csFile}"
# tests
find "${root}/tests" -name "*.h" >> "${csFile}"
find "${root}/tests" -name "*.cpp" >> "${csFile}"
find "${root}/tests" -name "*.cc" >> "${csFile}"

echo "Build cscope DB..."
oldDir=$( pwd )
cd ${root}
cscope -Rbqk
cd ${oldDir}

echo "Done."

